package com.qingyun.form.validator

import com.qingyun.form.items.BaseFormItem

/**
 * 校验结果
 */
class FormValidatorResult private constructor(
    val item: BaseFormItem?,//校验的表单项
    private val text: String?,//校验结果
) {
    /**
     * 校验失败时的提示信息
     */
    val message: String
        get() = text!!

    /**
     * 是否校验成功
     */
    fun successfully(): Boolean {
        return text == null
    }

    companion object {
        fun success(item: BaseFormItem?=null): FormValidatorResult {
            return FormValidatorResult(item, null)
        }

        fun error(item: BaseFormItem, message: String): FormValidatorResult {
            return FormValidatorResult(item, message)
        }
    }
}